package edu.sctu.zhangwang.month201506.day20150628.test_day0628.get_json;

import java.io.*;

/**
 * Created by Administrator on 2015/6/28.
 */
public class WriteData extends Thread {
    File file = new File("D://Json");
    File file1 = new File("D://Json/Json.txt");

    public void creatFile(String url, String parm) {
        file.mkdirs();
        GetData getData = new GetData();
        if (file1.exists()) {
            Thread thread = new Thread();
            try {
                System.out.println("等待5秒。。。");
                thread.sleep(5000);
                try {
                    FileOutputStream fileOutputStream = new FileOutputStream("D://Json/Json.txt");
                    try {
                        OutputStreamWriter writer = new OutputStreamWriter(fileOutputStream,"utf-8");
                        try {
                            writer.append(getData.write(url, parm));
                            System.out.println("数据录入中。。。");
                            writer.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }

                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } else {
            try {
                file1.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        WriteData writeData = new WriteData();
        writeData.creatFile("http://api.ii.com.cn/goods/apprec", "page=1&size=10");
    }
}
